package com.zxw.http;

import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.digest.MD5;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONObject;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.logging.SimpleFormatter;

/**
 * @projectName: util-cloud
 * @package: com.zxw.http
 * @className: Test
 * @author: zhangxuewei
 * @description:
 * @date: 2025/10/16 12:40
 * @version: 1.0
 */
public class Test {

    public static void main(String[] args) {
        String appId = "oa";
        String clientId = "16267e87744e4b02048dbad12aec59dc";
        String secretKey = "5b6b6fd6837c69e1ae20fab2b6d91299";

        JSONObject params = new JSONObject();
        params.put("tenantId", "000000");
        params.put("appId", appId);
        params.put("clientId", clientId);
        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
        String res = formatter.format(new Date());
        params.put("timestamp", res);

        String sign = SecureUtil.md5(appId + secretKey + res);
        params.put("sign", sign);

        params.put("grantType", "app");
        String apiResultStr = HttpUtil.createPost("http://127.0.0.1:8180/auth/login").header("clientid", clientId)
                .body(params.toString()).execute().body();
        JSONObject jsonObject = JSONObject.parseObject(apiResultStr);



//        if (jsonObject.get("code").toString().equals("200")) {
//            String token = JSONObject.parseObject(jsonObject.get("data").toString()).get("access_token").toString();
//            System.out.println(token);
//
//
//            List<String> xzryCodes = new ArrayList<>();
//            xzryCodes.add("230213009");
//            xzryCodes.add("230421001");
//
//            JSONObject paramsr = new JSONObject();
//            paramsr.put("mtPlanId", 1); // 保养计划ID
//            paramsr.put("requestId", 1802024); // OA请求主键
//            paramsr.put("mainUserCode", "230220017"); // 保养人
//            paramsr.put("mtUserCodes", xzryCodes); // 协助人
//            String apiResultStrr = HttpUtil.createPost("http://127.0.0.1:8180/api/dm/mt/formOa").header("clientid", clientId).header("authorization", "Bearer " + token)
//                    .body(paramsr.toString()).execute().body();
//            System.out.println(apiResultStrr);
//            JSONObject apiResult = JSONObject.parseObject(apiResultStrr);
//        } else {
//            // 获取token失败
//            String msg = jsonObject.get("msg").toString();
//            System.out.println(msg);
//        }


    }


}
